package org.example.my.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.example.my.model.BlogInfo;

import java.util.List;
@Mapper
public interface BlogMapper {
    //返回博客列表
    @Select("select * from blog where delete_flag = 0")
    public List<BlogInfo> selectBlogList();

    //根据博客Id,获取博客信息
    @Select("select * from blog where id=#{id} AND delete_flag = 0")
    public BlogInfo selectBlogById(Integer id);

    //更新
    public Integer updateBlog(BlogInfo blogInfo);

    //写博客
    @Insert("insert into blog(title,user_id,content) values(#{title},#{userId},#{content})")
    public Integer insertBlog(BlogInfo blogInfo);

    //根据博客Id,获取用户Id
    @Select("select user_id from blog where id = #{id}")
    public Integer selectUserIdById(Integer id);

    //根据id获取博客总数
    @Select("select count(*) from blog where delete_flag = 0 AND user_id = #{userid}")
    public Integer selectBlogCount(Integer userid);


}
